package lesson15;
import lesson14.Car;

public class CarShop {
	Car[] cars;
	static int carIndex = 0;
	static int currentCarIndex = carIndex;
	
	CarShop(int capacity)
	{
		this.cars = new Car[capacity];
	}
	
	boolean addCar(Car car)
	{
		if(this.carIndex < cars.length)
		{
			cars[this.carIndex++] = car;
			return true;
		}
		return false;
	}
	
	Car getNextCar() 
	{
		if(this.carIndex != cars.length-1)
			return cars[currentCarIndex+1];
		else
			return cars[0];
	}
	
	void sellNextCar(Person buyer) //get the next car and sell it to the buyer 
	{
		this.getNextCar().owner = buyer;
	}
	
	boolean removeCar(Car car) //removes the car from the shop. It must be called after the selling car to a buyer 
	{
		if(car.owner == null)
			return false;
		else
			car = null;
			return true;
	}
	
	void showAllCarsInTheShop() //print information for all the cars to the console
	{
		for (Car i : cars) {
			i.printInformation();
		}
	}
	
	public static void main(String[] args) {
		Car brukma1 = new Car("Golf", false, "pink");
		Car brukma2 = new Car("Lada", true, "white");
		Car brukma3 = new Car("Mazda", true, "gray");
		CarShop bitak = new CarShop(3);
		bitak.addCar(brukma1);
		bitak.addCar(brukma2);
		bitak.addCar(brukma3);
		bitak.sellNextCar(new Person());
		bitak.removeCar(brukma3);
		bitak.showAllCarsInTheShop();
	}
}
